package JavaBase;
/*
 *以(OO)面向对象的思想，编写简易的计算器(Calculator)，
 *设定属性包括：左操作数(numberA)、右操作数(numberB)，
 *方法包括：加法(add())、减法(sub())、乘法(mul())、除法(div())
 */
public class Calculator {
    private double numberA;
    private double numberB;
    public Calculator()
    {
        this.numberA=1;
        this.numberB=1;
    }
    public Calculator(double numberA,double numberB)
    {
        this.numberA=numberA;
        this.numberB=numberB;
    }

    public double getNumberA() {
        return numberA;
    }

    public void setNumberA(double numberA) {
        this.numberA = numberA;
    }

    public double getNumberB() {
        return numberB;
    }

    public void setNumberB(double numberB) {
        this.numberB = numberB;
    }
    public double add(double numberA,double numberB)
    {
        return numberA+numberB;
    }
    public double sub(double numberA,double numberB)
    {
        return numberA-numberB;
    }public double mul(double numberA,double numberB)
    {
        return numberA*numberB;
    }
    public double div(double numberA,double numberB)
    {
        if(numberB==0)
        {
            System.out.println("除数不能为0.");
            System.exit(1);
        }
        return numberA/numberB;
    }


}